﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;

/// <summary>
/// ORender 的摘要说明
/// </summary>
/// 静态页面生成方法
/// </summary>
/// <param name="filmname">要生成的静态页面的全名</param>
/// <param name="html">要生成静态页面的内容</param>
/// <summary>
public class ORender : System.Web.UI.Page
{
    public ORender()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public string strFileName = null;

    public string redirectURL = null;

    protected override void Render(HtmlTextWriter writer)

    {

        TextWriter tw = new StringWriter();

        base.Render(new HtmlTextWriter(tw));

        tw.Close();

        string html = tw.ToString();

        strFileName = Server.MapPath(".") + "/" + strFileName;

        writeHtml(strFileName, html);

        Response.Redirect(redirectURL);

    }

    public static void writeHtml(string filmname, string html)

    {

        System.Text.Encoding code = System.Text.Encoding.GetEncoding("utf-8");

        string htmlfilename = filmname;

        string str = html;

        StreamWriter sw = null;

        // 写文件

        try

        {

            sw = new StreamWriter(htmlfilename, false, code);

            sw.Write(str);

            sw.Flush();

        }

        catch (Exception ex)

        {

            HttpContext.Current.Response.Write(ex.Message);

            HttpContext.Current.Response.End();

        }

        finally

        {

            sw.Close();

        }
    }
}